//
// Created by Vincent_Vic on 2020/5/11.
//

#ifndef DATAORGANIZATION_CMAPBASE1TEST_H
#define DATAORGANIZATION_CMAPBASE1TEST_H
#include <iostream>
#include "CMapbase1.h"
using namespace std;

class CMapbase1Test {
public:
    void base1(){
        /*
        *     A
        *   /  \
        *  B   D
        * / \ / \
        * C F G H
        * \ /
        *  E
        *
        *   A B C D E F G H
        * A 0 1 0 1 0 0 0 0
        * B 1 0 1 0 0 1 0 0
        * C 0 1 0 0 1 0 0 0
        * D 1 0 0 0 0 0 1 1
        * E 0 0 1 0 0 1 0 0
        * F 0 1 0 0 1 0 0 0
        * G 0 0 0 1 0 0 0 1
        * H 0 0 0 1 0 0 1 0
        */

        CMap *pMap = new CMap(8);
        //创建节点
        Node *pNodeA = new Node('A');
        Node *pNodeB = new Node('B');
        Node *pNodeC = new Node('C');
        Node *pNodeD = new Node('D');
        Node *pNodeE = new Node('E');
        Node *pNodeF = new Node('F');
        Node *pNodeG = new Node('G');
        Node *pNodeH = new Node('H');
        //添加节点
        pMap-> addNode(pNodeA);
        pMap-> addNode(pNodeB);
        pMap-> addNode(pNodeC);
        pMap-> addNode(pNodeD);
        pMap-> addNode(pNodeE);
        pMap-> addNode(pNodeF);
        pMap-> addNode(pNodeG);
        pMap-> addNode(pNodeH);
        //设定图
        pMap-> setValueToMatrixForUndirectedGraph(0, 1);
        pMap->setValueToMatrixForUndirectedGraph(0, 3);
        pMap->setValueToMatrixForUndirectedGraph(1, 2);
        pMap->setValueToMatrixForUndirectedGraph(1, 5);
        pMap->setValueToMatrixForUndirectedGraph(3, 6);
        pMap->setValueToMatrixForUndirectedGraph(3, 7);
        pMap->setValueToMatrixForUndirectedGraph(6, 7);
        pMap->setValueToMatrixForUndirectedGraph(2, 4);
        pMap->setValueToMatrixForUndirectedGraph(4,5);

        pMap->printMatix();
        cout << endl;

        pMap->depthFirstTraverse(0);
        pMap->resetNode();
        cout << endl;
        pMap->breadthFirstTraverse(0);
    }

    /**
     * @param select  0 表示普利姆算法测试 ，1是克里斯卡尔算法
     */
    void primOrkruskalTest(int select){

        /**
                  A
               /  |  \
              B - C - E
               \ / \ /
                C   D

            A B C D E F
            0 1 2 3 4 5

            A-B 6 A-E 5 A-F 1
            B-C 3 B-F 2
            C-F 8 C-D 7
            D-F 4 D-E 2
            E-F 9
         */

        CMap *pMap = new CMap(6);
        //创建节点
        Node *pNodeA = new Node('A');
        Node *pNodeB = new Node('B');
        Node *pNodeC = new Node('C');
        Node *pNodeD = new Node('D');
        Node *pNodeE = new Node('E');
        Node *pNodeF = new Node('F');

        //添加节点
        pMap-> addNode(pNodeA);
        pMap-> addNode(pNodeB);
        pMap-> addNode(pNodeC);
        pMap-> addNode(pNodeD);
        pMap-> addNode(pNodeE);
        pMap-> addNode(pNodeF);

        //设定图
        pMap-> setValueToMatrixForUndirectedGraph(0, 1, 6);
        pMap-> setValueToMatrixForUndirectedGraph(0,4, 5);
        pMap-> setValueToMatrixForUndirectedGraph(0, 5, 1);
        pMap-> setValueToMatrixForUndirectedGraph(1, 2, 3);
        pMap-> setValueToMatrixForUndirectedGraph(1, 5, 2);
        pMap-> setValueToMatrixForUndirectedGraph(2, 5, 8);
        pMap-> setValueToMatrixForUndirectedGraph(2, 3, 7);
        pMap-> setValueToMatrixForUndirectedGraph(3, 5, 4);
        pMap-> setValueToMatrixForUndirectedGraph(3, 4, 2);
        pMap-> setValueToMatrixForUndirectedGraph(4, 5, 9);

        pMap->printMatix();
        cout << endl;

        if (select == 0){
            pMap->primTree(0);
        } else{
            pMap->kruskalTree();
        }

    }
};


#endif //DATAORGANIZATION_CMAPBASE1TEST_H
